import './projectlist.scss'
import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
import Search from 'vux/src/components/search/index.vue'
import XProgress from 'vux/src/components/x-progress/index.vue'
import Tab from 'vux/src/components/tab/tab.vue'
import TabItem from 'vux/src/components/tab/tab-item.vue'
import Sticky from 'vux/src/components/sticky/index.vue'
import Flexbox from 'vux/src/components/flexbox/flexbox.vue'
import FlexboxItem from 'vux/src/components/flexbox/flexbox-item.vue'
import Scroller from 'vux/src/components/scroller/index.vue'
import Loading from 'vux/src/components/loading/index.vue'
export default {
  name: 'searchProject',
  components: {
    Search,
    XProgress,
    Tab,
    TabItem,
    Sticky,
    Flexbox,
    FlexboxItem,
    Scroller,
    Loading
  },
  data () {
    return {
      eventListQB: [],
      use_pullup:true,
      pullup_con:true,
      pageNo:1,
      pageSize:10
    }
  },

  mounted () {
    let _this=this;
    let donateAreaId = this.$route.query.donateAreaId
    http.post(CONSTANT.DONATES_BY_AREAID, {areaId: donateAreaId, pageNo: this.pageNo, pageSize: this.pageSize}, (res) => {
      if (res.code == 200) {
        _this.eventListQB = res.list
      }
      // console.log(res)
      // if (this.value != '') {
      //   if (res.errmsg == '没有更多的项目') {
      //     return
      //   }
      //   this.allnumber = res.list[0].number
      //   this.eventListsearch = res.list
      //   this.eventListQB = this.eventListsearch
      //   this.eventListjinqi = ''
      //   this.eventListwangqi = ''
      // }
    })
  },
  methods: {

    goProject (e) {
      // window.sessionStorage.setItem('event_id', e)
      // if (isTh == 1) {
      //   this.$router.push({path: '/togetherShop', query: {event_id: e}})
      //   return
      // }
      // this.$router.push({path: '/Project', query: {event_id: e}})
    },

    onScrollBottom () {
      this.loadingShow = true
      if (this.eventListjinqi != '' && this.isA == true) {
        this.pageNoJinqi++
        this.jinqiEvent(this.$route.query.type, this.$route.query.areaId)
      }
      if (this.eventListwangqi != '' && this.isB == true) {
        this.pageNoWangqi++
        this.wangqiEvent(this.$route.query.type)
      }
      if (this.eventListsearch != '') {
        this.pageNosearch++
        http.post(CONSTANT.EVENT_SEARCH, {keyWords: this.value, pageNo: this.pageNosearch, pageSize: this.pageSize}, (res) => {
          this.loadingShow = false
          if (res.code == 200) {
            if (res.errmsg == '没有更多的项目') {
              this.pageNosearch--
              return
            }
            if (this.value != '') {
              this.eventListsearch = this.eventListsearch.concat(res.list)
              this.eventListQB = this.eventListsearch
              this.$nextTick(() => {
                this.$refs.scroller.donePullup()
                this.$refs.scroller.reset()
              })
            }
          }
        })
      }
    },
    setFocus () {
      this.$refs.search.setFocus()
      console.log('setFocus')
    },
    resultClick (item) {
      this.$refs.search.setBlur()
      console.log('resultClick')
    },
    getResult (val) {
      console.log('on-change', val)
    },
    onSubmit () {
      this.$refs.search.setBlur()
    },
    onFocus () {
      console.log('on focus')
    },
    onCancel () {
      // window.history.go(-1)
      this.$refs.search.setBlur()
      // this.eventListQB = []
    }
  }
}
function getResult (val) {
  let rs = []
  for (let i = 0; i < 20; i++) {
    rs.push({
      title: `${val} result: ${i + 1} `,
      other: i
    })
  }
  return rs
}
